﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Script.Serialization;
using TaxBusiness.BLL;
using TaxBusiness.Model;

namespace WebSites.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult ReLogin()
        {
            return View();
        }

        public ActionResult Login()
        {
            string userName = Request.Form["login"].ToString();
            string pwd = Request.Form["password"].ToString();
            TaxBusiness.Model.Users user = new Users();
            Message msg;
            UserBLL userbll = new UserBLL();
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            
            user = userbll.CheckLogin(userName);
            if (user == null)
            {
                msg = new Message(false, "用户不存在！");
            }
            else
            {
                if (user.PWD != pwd)
                    msg = new Message(false, "密码错误！");
                else
                {
                    Session["UserName"] = user.UserName;
                    Session["TrueName"] = user.TrueName;
                    Session["UserID"] = user.ID;
                    Session["OfficeID"] = user.OfficeID;
                    Session["AuthID"] = user.AuthID;
                    msg = new Message(true, "验证通过！");
                }
            }
            string json = serializer.Serialize(msg);
            return Content(json);
        }

    }
}
